$ ()->
    initScrollListener()
    initMenuToggler()

initScrollListener = ()->
    to = null;
    $(window).scroll ()->
        clearTimeout(to) if to

        scrollListener = ()->
            st = $(window).scrollTop()
            hh = $('header').height()

            if st>hh/2
                $('html').addClass 'scroll'
            else
                $('html').removeClass 'scroll'

        to = setTimeout scrollListener, 100

initMenuToggler = ()->
    speed = 300;
    menu  = $ 'menu'
    menu.children('.toggler').click ()->
        siblings = $(this).siblings 'li'
        if menu.hasClass('opened')
            menu
                .removeClass('opened')
                .animate
                    left: '100%'
                ,
                    duration: speed,
                    complete: ()->
                        $(this).css 'display', ''
        else
            menu
                .addClass 'opened'
                .animate
                    left: 0
                ,
                    duration: speed